/*
 *  POJ1753: Flip Game
 */

/*-------- Includes --------*/
#include <stdio.h>
#include <stdlib.h>
#include <deque>

using namespace std;

/*-------- Defines --------*/

/*-------- Types --------*/
class Chess {
public:
    unsigned int stat;
    int          step;

public:
    Chess()                            { stat = 0; step = 0;                   }
    Chess(unsigned int stat, int step) { this->stat = stat; this->step = step; }
    ~Chess()                           {                                       }

    unsigned int getMap() { return stat & 0xffff; }
    int          getMaxSetBit();
};

/*-------- Global Variables --------*/
const unsigned int STAT_MASK[16] = {
    0x0013, 0x0027, 0x004E, 0x008C,
    0x0131, 0x0272, 0x04E4, 0x08C8,
    0x1310, 0x2720, 0x4E40, 0x8C80,
    0x3100, 0x7200, 0xE400, 0xC800
};

/*-------- Function prototypes --------*/
int bfs(unsigned int srcmap, unsigned int dstmap);

/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    int          ch;
    unsigned int map  = 0;
    unsigned int mask = 1;

    // get input
    while ((ch = getchar()) != EOF) {
        if      (ch == 'b')  { map |= mask; mask <<= 1; }
        else if (ch == 'w')  {              mask <<= 1; }
        else                 continue;
    }

    int w = bfs(0, map);
    int b = bfs(0xFFFF, map);

    if (w < 0 && b < 0) printf("Impossible");
    else                printf("%d\n", w < b ? w : b);

    return 0;
}

/*-------- Chess::Methods --------*/
int Chess::getMaxSetBit()
{
    unsigned int mask = 0x80000000;

    for (int i = 15; i >= 0; i--, mask >>= 1)
        if (stat & mask) return i;

    return -1;
}

/*-------- Functions --------*/
int bfs(unsigned int srcmap, unsigned int dstmap)
{
    Chess        cur(srcmap, 0);
    deque<Chess> q;

    // enqueue the first element
    q.push_back(cur);

    // breadth first search
    while (!q.empty()) {
        cur = q.front();
        q.pop_front();

        // base case
        if (cur.getMap() == dstmap) break;

        for (int i = cur.getMaxSetBit() + 1; i < 16; i++) {
            Chess c;

            c.stat =  cur.stat ^ STAT_MASK[i];
            c.stat |= 1 << (i + 16);
            c.step =  cur.step + 1;

            q.push_back(c);
        }
    }

    if (cur.getMap() == dstmap) return cur.step;

    return -1;
}
